{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "96bf793d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "b865244f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([20, 8, 128])\n"
     ]
    }
   ],
   "source": [
    "fc = torch.nn.Linear(70, 128)\n",
    "m = torch.nn.Conv1d(128, 512, 5, stride=1)\n",
    "m2 = torch.nn.Conv1d(512, 512, 3, stride=1)\n",
    "rnn = torch.nn.GRU(512, 512, 3, batch_first=True)\n",
    "input = torch.randn(20, 8, 70) # B, T, D\n",
    "output = fc(input)\n",
    "print(output.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "8697ece9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([20, 512, 2])\n",
      "torch.Size([20, 2, 512])\n"
     ]
    }
   ],
   "source": [
    "output=output.permute([0,2,1]) # B, D, T \n",
    "output = m(output)\n",
    "output = m2(output)\n",
    "print(output.shape)\n",
    "output=output.permute([0,2,1]) # B, T, D\n",
    "output= rnn(output)\n",
    "\n",
    "\n",
    "print(output[0].shape)\n",
    "input = torch.randn(5, 3, 10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "361571d9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Loading data...\n",
      "done.\n",
      "2  sequences\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "import h5py\n",
    "import sys\n",
    "\n",
    "\n",
    "input_and_output_dim=138\n",
    "bin_file_name=\"test.output\"\n",
    "data = np.fromfile(bin_file_name, dtype='float32')\n",
    "data = np.reshape(data, (len(data)//input_and_output_dim, input_and_output_dim))\n",
    "h5f = h5py.File(\"training.h5\", 'w');\n",
    "h5f.create_dataset('data', data=data)\n",
    "h5f.close()\n",
    "\n",
    "\n",
    "print('Loading data...')\n",
    "with h5py.File('training.h5', 'r') as hf:\n",
    "    all_data = hf['data'][:]\n",
    "print('done.')\n",
    "\n",
    "window_size = 2000\n",
    "\n",
    "nb_sequences = len(all_data)//window_size\n",
    "print(nb_sequences, ' sequences')\n",
    "x_train = all_data[:nb_sequences*window_size, :70]\n",
    "x_train = np.reshape(x_train, (nb_sequences, window_size, 70))\n",
    "\n",
    "y_train = np.copy(all_data[:nb_sequences*window_size, 70:])\n",
    "y_train = np.reshape(y_train, (nb_sequences, window_size, 68))\n",
    "\n",
    "all_data = 0\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "19d76b37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(2, 2000, 70)"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "c78d9775",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n",
       "       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n",
       "       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n",
       "       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n",
       "       1., 0.], dtype=float32)"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x_train[0,1]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
